<?php

    class WZ_Bootstrap
    {
        static $_instance;
        public $_classResources;
        
        public static function getInstance()
        {
            if (null === self::$_instance) {
                self::$_instance = new self();
            }
            return self::$_instance;
        }
        
        public function __construct()
        {
            require_once APPLICATION_PATH . '/Bootstrap.php';
        }
        
        public function run()
        {
            $bootstrap = new \App_bootstrap();
            $methods = $bootstrap->getClassResources();
            foreach ($methods as $value => $method) {
                $bootstrap->$method();
            }
        }
        
        public function getClassResources()
        {
            if (null === $this->_classResources) {
                if (version_compare(PHP_VERSION, '5.2.6') === -1) {
                    $class        = new \ReflectionObject($this);
                    $classMethods = $class->getMethods();
                    $methodNames  = array();

                    foreach ($classMethods as $method) {
                        $methodNames[] = $method->getName();
                    }
                } else {
                    $methodNames = get_class_methods($this);
                }

                $this->_classResources = array();
                foreach ($methodNames as $method) {
                    if (5 < strlen($method) && '_init' === substr($method, 0, 5)) {
                        $this->_classResources[strtolower(substr($method, 5))] = $method;
                    }
                }
            }
            return $this->_classResources;
        }
    }